<script>
//刚刚，几分钟，几小时前

var time
function timefn(oldTime)
{
    // var oldTime=new Date(timedata)
    var newTime= new Date().getTime()
    var time=newTime-oldTime.getTime()
    console.log(oldTime);
    // console.log(newTime);
    // console.log(oldTime);
    // console.log(time);
    if((time/1000)<60)
    {
        document.write("刚刚")
    }
    else if(parseInt(time/1000/60)<60)
    {
        document.write(parseInt(time/1000/60)+"分钟前")
    }
    else if(parseInt(time/1000/60/60)<24)
    {
        document.write(parseInt(time/1000/60/60)+"小时前")
    }
    else if(parseInt(time/1000/60/60/24)<31)
    {
        document.write(parseInt(time/1000/60/60/24)+"天前")
    }
    else if(parseInt(time/1000/60/60/24/30)<12)
    {
        document.write(parseInt(time/1000/60/60/24/30)+"个月前")
    }
    else 
    {
        document.write(parseInt(time/1000/60/60/24/30/12)+"年前")
    }  
}

timefn(time=new Date(2021,7,26,11,44,35))
</script>